package com.huawei.appmarket.service.store.awk.card;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appgallery.horizontalcard.api.card.BaseHorizontalItemCard;
import com.huawei.appmarket.service.store.awk.bean.HorizontalAppWelfareGiftItemCardBean;
import com.huawei.appmarket.service.store.awk.bean.HorizontalAppWelfareItemCardBean;
import com.huawei.fastengine.fastview.download.utils.PackageUtils;
import huawei.widget.HwTextView;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Locale;
import o.ces;
import o.cet;
import o.ceu;
import o.cgz;
import o.chc;
import o.chy;
import o.cih;
import o.cil;
import o.cim.a;
import o.clk;
import o.Logger;
import o.ContentManager;
import o.eib;
import o.ein;
import o.epv;
import o.epw;
import o.eqx;
import o.evf;
import o.evx;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public class HorizontalAppWelfareItemCard extends BaseHorizontalItemCard implements clk {
    private ImageView ʻ;
    private RelativeLayout ʻॱ;
    private ImageView ʼ;
    private HwTextView ʽ;
    private HwTextView ˊॱ;
    private ImageView ˋ;
    private LinearLayout ˋˋ;
    private HwTextView ˋॱ;
    private RelativeLayout ˋᐝ;
    private LinearLayout ˎˎ;
    private HwTextView ˏॱ;
    private HwTextView ͺ;
    private HwTextView ॱˊ;
    private RelativeLayout ॱˋ;
    private HwTextView ॱˎ;
    private ImageView ॱॱ;
    private RelativeLayout ॱᐝ;
    private HwTextView ᐝ;
    private RelativeLayout ᐝॱ;

    static class e implements ces {
        WeakReference<HorizontalAppWelfareItemCardBean> ˊ;
        HorizontalAppWelfareItemCard ˋ;
        WeakReference<Context> ˎ;
        WeakReference<HorizontalAppWelfareGiftItemCardBean> ˏ;
        WeakReference<chy> ॱ;

        e(HorizontalAppWelfareItemCardBean horizontalAppWelfareItemCardBean, HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean, chy o_chy, Context context) {
            this.ˊ = new WeakReference(horizontalAppWelfareItemCardBean);
            this.ˏ = new WeakReference(horizontalAppWelfareGiftItemCardBean);
            this.ॱ = new WeakReference(o_chy);
            this.ˎ = new WeakReference(context);
            this.ˋ = new HorizontalAppWelfareItemCard(context);
            this.ˋ.ˊᐝ = horizontalAppWelfareItemCardBean;
        }

        public void onResult(int i) {
            HorizontalAppWelfareItemCard.ˏ(i, (HorizontalAppWelfareItemCardBean) this.ˊ.get(), (HorizontalAppWelfareGiftItemCardBean) this.ˏ.get());
            HorizontalAppWelfareItemCard.ˎ(i, (chy) this.ॱ.get(), (HorizontalAppWelfareGiftItemCardBean) this.ˏ.get(), (HorizontalAppWelfareItemCardBean) this.ˊ.get(), (Context) this.ˎ.get(), this.ˋ);
        }
    }

    public /* synthetic */ CardBean ˌ() {
        return ʻ();
    }

    public HorizontalAppWelfareItemCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        ˋ((DownloadButton) view.findViewById(j.ˊᶦ));
        this.ˋ = (ImageView) view.findViewById(j.ʻˊ);
        this.ᐝ = (HwTextView) view.findViewById(j.ˊᶡ);
        this.ʽ = (HwTextView) view.findViewById(j.ˊۥ);
        this.ॱॱ = (ImageView) view.findViewById(j.ꞌˋ);
        this.ʻ = (ImageView) view.findViewById(j.ʼⁱ);
        this.ʼ = (ImageView) view.findViewById(j.ˆᐝ);
        this.ˋॱ = (HwTextView) view.findViewById(j.ﹶॱ);
        this.ˏॱ = (HwTextView) view.findViewById(j.﹍);
        this.ͺ = (HwTextView) view.findViewById(j.ʼꜝ);
        this.ˊॱ = (HwTextView) view.findViewById(j.ʼﹶ);
        this.ॱˊ = (HwTextView) view.findViewById(j.ˇˋ);
        this.ॱˎ = (HwTextView) view.findViewById(j.ˇᐝ);
        this.ॱˋ = (RelativeLayout) view.findViewById(j.ˋʳ);
        this.ᐝॱ = (RelativeLayout) view.findViewById(j.ˊᐠ);
        this.ʻॱ = (RelativeLayout) view.findViewById(j.ˊᐣ);
        this.ॱᐝ = (RelativeLayout) view.findViewById(j.ˊᵕ);
        this.ˋᐝ = (RelativeLayout) view.findViewById(j.ˊᕀ);
        this.ˎˎ = (LinearLayout) view.findViewById(j.ˋˆ);
        this.ˋˋ = (LinearLayout) view.findViewById(j.ˊᑊ);
        ʽ(view);
        ʼ();
        return this;
    }

    public HorizontalAppWelfareItemCardBean ʻ() {
        if (this.ˊᐝ instanceof HorizontalAppWelfareItemCardBean) {
            return (HorizontalAppWelfareItemCardBean) this.ˊᐝ;
        }
        return null;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof HorizontalAppWelfareItemCardBean) {
            HorizontalAppWelfareItemCardBean horizontalAppWelfareItemCardBean = (HorizontalAppWelfareItemCardBean) cardBean;
            this.ᐝ.setText(horizontalAppWelfareItemCardBean.v_());
            ˏ(horizontalAppWelfareItemCardBean);
            this.ʽ.setText(horizontalAppWelfareItemCardBean.ˎͺ());
            ॱॱ();
            if (horizontalAppWelfareItemCardBean.ʻˋ() == null) {
                Logger.ˏ("HorizontalAppWelfareItemCard", "setData bean.getAppWelfare_() == null");
                return;
            }
            for (int i = 0; i < horizontalAppWelfareItemCardBean.ʻˋ().size(); i++) {
                HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean = (HorizontalAppWelfareGiftItemCardBean) horizontalAppWelfareItemCardBean.ʻˋ().get(i);
                switch (i) {
                    case 0:
                        this.ʻॱ.setTag(horizontalAppWelfareGiftItemCardBean);
                        this.ˋॱ.setText(horizontalAppWelfareGiftItemCardBean.v_());
                        ˋ(this.ˏॱ, horizontalAppWelfareGiftItemCardBean);
                        ˊ(this.ॱॱ, horizontalAppWelfareGiftItemCardBean.ॱ());
                        this.ॱॱ.setContentDescription(horizontalAppWelfareGiftItemCardBean.v_());
                        break;
                    case 1:
                        this.ॱᐝ.setTag(horizontalAppWelfareGiftItemCardBean);
                        this.ͺ.setText(horizontalAppWelfareGiftItemCardBean.v_());
                        ˋ(this.ˊॱ, horizontalAppWelfareGiftItemCardBean);
                        ˊ(this.ʻ, horizontalAppWelfareGiftItemCardBean.ॱ());
                        this.ʻ.setContentDescription(horizontalAppWelfareGiftItemCardBean.v_());
                        break;
                    case 2:
                        this.ˋᐝ.setTag(horizontalAppWelfareGiftItemCardBean);
                        this.ॱˊ.setText(horizontalAppWelfareGiftItemCardBean.v_());
                        ˋ(this.ॱˎ, horizontalAppWelfareGiftItemCardBean);
                        ˊ(this.ʼ, horizontalAppWelfareGiftItemCardBean.ॱ());
                        this.ʼ.setContentDescription(horizontalAppWelfareGiftItemCardBean.v_());
                        break;
                    default:
                        break;
                }
            }
        }
    }

    private void ˏ(HorizontalAppWelfareItemCardBean horizontalAppWelfareItemCardBean) {
        if (TextUtils.isEmpty(horizontalAppWelfareItemCardBean.ॱˑ())) {
            eqx.ˏ(this.ˋ, horizontalAppWelfareItemCardBean.ॱˌ(), "app_default_icon");
        } else {
            eqx.ॱ(this.ˋ, horizontalAppWelfareItemCardBean.ॱˑ(), "app_default_icon");
        }
        this.ˋ.setContentDescription(horizontalAppWelfareItemCardBean.v_());
    }

    private void ʼ() {
        int ˋ = chc.ˋ();
        LayoutParams layoutParams = this.ॱˋ.getLayoutParams();
        layoutParams.width = epv.ˎ(this.ʼॱ, eib.ʻ(), ˋ);
        this.ॱˋ.setLayoutParams(layoutParams);
    }

    private void ˋ(HwTextView hwTextView, HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean) {
        if (horizontalAppWelfareGiftItemCardBean.ॱ().contentEquals("campaign")) {
            ˊ(hwTextView, horizontalAppWelfareGiftItemCardBean);
        } else if (horizontalAppWelfareGiftItemCardBean.ॱ().contentEquals("forumGift") || horizontalAppWelfareGiftItemCardBean.ॱ().contentEquals("gift")) {
            ॱ(hwTextView, horizontalAppWelfareGiftItemCardBean);
        }
    }

    private void ˊ(HwTextView hwTextView, HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean) {
        String ˏ = ˏ(horizontalAppWelfareGiftItemCardBean.ʽ());
        Object string = this.ʼॱ.getResources().getString(n.ˋʽ, new Object[]{ˏ});
        Object ˊ = horizontalAppWelfareGiftItemCardBean.ˊ();
        if (TextUtils.isEmpty(ˊ)) {
            hwTextView.setText(string);
        } else {
            hwTextView.setText(" · " + string);
        }
    }

    private void ॱ(HwTextView hwTextView, HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean) {
        String str = "";
        if (-1 == horizontalAppWelfareGiftItemCardBean.ꜟ()) {
            str = this.ʼॱ.getString(n.ˊﾟ, new Object[]{ˋ(4)});
        } else {
            str = this.ʼॱ.getString(n.ˊﾟ, new Object[]{ˋ(horizontalAppWelfareGiftItemCardBean.ꜟ())});
        }
        Object obj = "";
        if (horizontalAppWelfareGiftItemCardBean.ॱ().contentEquals("forumGift")) {
            obj = ˎ(horizontalAppWelfareGiftItemCardBean);
        } else {
            if (1 < horizontalAppWelfareGiftItemCardBean.ㆍ()) {
                String string = this.ʼॱ.getString(n.ˊꞌ, new Object[]{Integer.valueOf(r2)});
                obj = this.ʼॱ.getString(n.ˋʿ, new Object[]{string});
            }
        }
        Object ˊ = horizontalAppWelfareGiftItemCardBean.ˊ();
        StringBuilder stringBuilder = new StringBuilder(str);
        if (!TextUtils.isEmpty(obj)) {
            stringBuilder.append(" · ").append(obj);
            if (!TextUtils.isEmpty(ˊ)) {
                stringBuilder.append(" · ").append(ˊ);
            }
        } else if (!TextUtils.isEmpty(ˊ)) {
            stringBuilder.append(" · ").append(ˊ);
        }
        hwTextView.setText(stringBuilder.toString());
    }

    private String ˎ(HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean) {
        if (!horizontalAppWelfareGiftItemCardBean.ꜞ()) {
            return "";
        }
        if (horizontalAppWelfareGiftItemCardBean.ꓸ() == horizontalAppWelfareGiftItemCardBean.ᶥ()) {
            return this.ʼॱ.getString(n.ˊﾞ, new Object[]{Integer.valueOf(horizontalAppWelfareGiftItemCardBean.ꓸ())});
        }
        return this.ʼॱ.getString(n.ˊᐧ, new Object[]{Integer.valueOf(horizontalAppWelfareGiftItemCardBean.ꓸ()), Integer.valueOf(horizontalAppWelfareGiftItemCardBean.ᶥ())});
    }

    private void ˊ(ImageView imageView, String str) {
        if (str.contentEquals("campaign")) {
            imageView.setImageDrawable(evf.ˋ(this.ʼॱ, o.ewm.e.ˎˏ));
        } else if (str.contentEquals("gift")) {
            imageView.setImageDrawable(evf.ˋ(this.ʼॱ, o.ewm.e.ˑ));
        } else if (str.contentEquals("forumGift")) {
            imageView.setImageDrawable(evf.ˋ(this.ʼॱ, o.ewm.e.ˏˎ));
        }
    }

    private void ॱॱ() {
        if (ʻ() == null || ʻ().ʻˋ() == null) {
            Logger.ˏ("HorizontalAppWelfareItemCard", "setData setViewsVisibility getBean() == null || getBean().getAppWelfare_() == null");
            return;
        }
        if (ʻ().ʻˋ().size() < 3) {
            this.ˋˋ.setVisibility(0);
            this.ˎˎ.setVisibility(8);
        } else {
            this.ˋˋ.setVisibility(8);
            this.ˎˎ.setVisibility(0);
        }
        if (ʻ().ʻˋ().size() > 0) {
            this.ʻॱ.setVisibility(0);
        } else {
            this.ʻॱ.setVisibility(8);
        }
        if (ʻ().ʻˋ().size() > 1) {
            this.ॱᐝ.setVisibility(0);
        } else {
            this.ॱᐝ.setVisibility(8);
        }
        if (ʻ().ʻˋ().size() > 2) {
            this.ˋᐝ.setVisibility(0);
        } else {
            this.ˋᐝ.setVisibility(8);
        }
    }

    public void ᐝ(int i) {
        if (i % 3 == 0) {
            ॱ(evf.ˋ(this.ʼॱ, o.ewm.e.ॱॱ));
        } else if (i % 3 == 1) {
            ॱ(evf.ˋ(this.ʼॱ, o.ewm.e.ᐝ));
        } else if (i % 3 == 2) {
            ॱ(evf.ˋ(this.ʼॱ, o.ewm.e.ʽ));
        }
    }

    private void ॱ(Drawable drawable) {
        if (epw.ˏ()) {
            drawable.setAlpha(51);
        } else {
            drawable.setAlpha(255);
        }
        this.ॱˋ.setBackground(drawable);
    }

    public int ˊ() {
        return h.ͺˎ;
    }

    public int ˎ() {
        return h.ͺˎ;
    }

    public void ॱ(final chy o_chy) {
        this.ᐝॱ.setOnClickListener(new evx(this) {
            final /* synthetic */ HorizontalAppWelfareItemCard ˋ;

            public void ˋ(View view) {
                o_chy.ˏ(0, this.ˋ);
            }
        });
        OnClickListener anonymousClass3 = new evx(this) {
            final /* synthetic */ HorizontalAppWelfareItemCard ˋ;

            public void ˋ(View view) {
                if (this.ˋ.ʻ() != null) {
                    HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean = (HorizontalAppWelfareGiftItemCardBean) view.getTag();
                    if (horizontalAppWelfareGiftItemCardBean == null) {
                        return;
                    }
                    if (horizontalAppWelfareGiftItemCardBean.ॱ().equals("forumGift")) {
                        this.ˋ.ˊ(o_chy, horizontalAppWelfareGiftItemCardBean);
                    } else {
                        HorizontalAppWelfareItemCard.ॱ(o_chy, this.ˋ.ʻ(), horizontalAppWelfareGiftItemCardBean, this.ˋ.ʼॱ);
                    }
                }
            }
        };
        this.ʻॱ.setOnClickListener(anonymousClass3);
        this.ॱᐝ.setOnClickListener(anonymousClass3);
        this.ˋᐝ.setOnClickListener(anonymousClass3);
        anonymousClass3 = new evx(this) {
            final /* synthetic */ HorizontalAppWelfareItemCard ॱ;

            public void ˋ(View view) {
                if (this.ॱ.ʻ() != null) {
                    this.ॱ.ˊ(o_chy, null);
                }
            }
        };
        this.ˎˎ.setOnClickListener(anonymousClass3);
        this.ˋˋ.setOnClickListener(anonymousClass3);
    }

    private void ˊ(chy o_chy, HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean) {
        if (!ˊॱ()) {
            new ceu((Activity) this.ʼॱ).ˊ(new cet(PackageUtils.HWGAMEBOX_PACKAGE_NAME, "gamebox", 100200110), new e(ʻ(), horizontalAppWelfareGiftItemCardBean, o_chy, this.ʼॱ));
        } else if (horizontalAppWelfareGiftItemCardBean != null) {
            ॱ(o_chy, ʻ(), horizontalAppWelfareGiftItemCardBean, this.ʼॱ);
        } else {
            ॱ(o_chy, ʻ(), this);
        }
    }

    public ArrayList<String> ॱ() {
        ArrayList<String> arrayList = new ArrayList();
        if (ʻ() == null || ʻ().ॱॱ() == null) {
            return arrayList;
        }
        arrayList.add(ˎ(ʻ().ॱॱ()));
        if (ʻ().ʻˋ() == null) {
            return arrayList;
        }
        for (int i = 0; i < ʻ().ʻˋ().size(); i++) {
            HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean = (HorizontalAppWelfareGiftItemCardBean) ʻ().ʻˋ().get(i);
            if (!(horizontalAppWelfareGiftItemCardBean == null || horizontalAppWelfareGiftItemCardBean.ॱॱ() == null)) {
                arrayList.add(ˎ(horizontalAppWelfareGiftItemCardBean.ॱॱ()));
            }
        }
        return arrayList;
    }

    private String ˎ(String str) {
        StringBuilder stringBuilder = new StringBuilder(256);
        stringBuilder.append(str);
        stringBuilder.append("#$#");
        if (ʻ().u_() != null) {
            stringBuilder.append(ʻ().u_());
        }
        return stringBuilder.toString();
    }

    private static void ˎ(int i, chy o_chy, HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean, HorizontalAppWelfareItemCardBean horizontalAppWelfareItemCardBean, Context context, HorizontalAppWelfareItemCard horizontalAppWelfareItemCard) {
        if (i == 2000 || i == 2001 || i == 2002) {
            ˏ(o_chy, horizontalAppWelfareGiftItemCardBean, horizontalAppWelfareItemCardBean, context, horizontalAppWelfareItemCard);
        } else if (i == 2100 || i == 2101 || i == 2102 || i == 2103 || i == 2200 || i == 2201 || i == 2202 || i == 2300 || i == 2301) {
            cil.ˋ(context, new a(horizontalAppWelfareItemCard.ʻ()).ˋ());
        }
    }

    private static void ˏ(chy o_chy, HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean, HorizontalAppWelfareItemCardBean horizontalAppWelfareItemCardBean, Context context, HorizontalAppWelfareItemCard horizontalAppWelfareItemCard) {
        if (horizontalAppWelfareGiftItemCardBean != null) {
            ॱ(o_chy, horizontalAppWelfareItemCardBean, horizontalAppWelfareGiftItemCardBean, context);
        } else {
            ॱ(o_chy, horizontalAppWelfareItemCardBean, horizontalAppWelfareItemCard);
        }
    }

    private static void ˏ(int i, HorizontalAppWelfareItemCardBean horizontalAppWelfareItemCardBean, HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean) {
        if (horizontalAppWelfareGiftItemCardBean != null) {
            ein.ˊ(i, PackageUtils.HWGAMEBOX_PACKAGE_NAME, horizontalAppWelfareGiftItemCardBean.ॱॱ());
        } else {
            ein.ˊ(i, PackageUtils.HWGAMEBOX_PACKAGE_NAME, horizontalAppWelfareItemCardBean.י());
        }
    }

    private static void ॱ(chy o_chy, HorizontalAppWelfareItemCardBean horizontalAppWelfareItemCardBean, HorizontalAppWelfareGiftItemCardBean horizontalAppWelfareGiftItemCardBean, Context context) {
        horizontalAppWelfareGiftItemCardBean.ˊˋ(horizontalAppWelfareItemCardBean.u_());
        cih baseDistCard = new BaseDistCard(context);
        baseDistCard.ˏ(horizontalAppWelfareGiftItemCardBean);
        o_chy.ˏ(0, baseDistCard);
    }

    private static void ॱ(chy o_chy, HorizontalAppWelfareItemCardBean horizontalAppWelfareItemCardBean, HorizontalAppWelfareItemCard horizontalAppWelfareItemCard) {
        String ॱॱ = horizontalAppWelfareItemCardBean.ॱॱ();
        horizontalAppWelfareItemCardBean.ॱ(horizontalAppWelfareItemCardBean.י());
        o_chy.ˏ(0, horizontalAppWelfareItemCard);
        horizontalAppWelfareItemCardBean.ॱ(ॱॱ);
    }

    private boolean ˊॱ() {
        return PackageUtils.HWGAMEBOX_PACKAGE_NAME.equals(ContentManager.getInstant().getContext().getPackageName());
    }

    private String ˏ(long j) {
        if (j != -1) {
            return DateUtils.formatDateTime(this.ʼॱ, j, 131092);
        }
        return "";
    }

    private String ˋ(int i) {
        int i2;
        if ("zh".equals(ˎ(this.ʼॱ))) {
            if (10000 > i) {
                return String.valueOf(i);
            }
            i2 = i / 10000;
        } else if (1000 > i) {
            return String.valueOf(i);
        } else {
            i2 = i / 1000;
        }
        return this.ʼॱ.getResources().getQuantityString(i.ᐝॱ, i2, new Object[]{Integer.valueOf(i2)});
    }

    private String ˎ(Context context) {
        String str = "";
        Resources resources = context.getResources();
        if (resources == null) {
            return str;
        }
        Configuration configuration = resources.getConfiguration();
        if (configuration == null) {
            return str;
        }
        Locale locale = configuration.locale;
        if (locale != null) {
            return locale.getLanguage();
        }
        return str;
    }
}
